package 剑指;

public class offer27 {
    class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x;}
    }
    public TreeNode mirrorTree(TreeNode root) {
        // root为空的时候直接返回null
        if(root == null) return null;
        // 左右子树为空直接返回该节点
        if(root.left == null && root.right == null) return root;
        // 交换左右节点
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        // 处理左子树
        mirrorTree(root.left);
        // 处理右子树
        mirrorTree(root.right);
        return root;
    }
}
